package sys.screen;

import java.awt.Component;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.SQLException;
import java.text.NumberFormat;
import java.util.List;
import javax.print.*;
import javax.swing.ImageIcon;
import javax.swing.JTable;
import javax.swing.SwingWorker;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import sys.bean.PedidoBean;
import sys.dao.PedidoDao;
import sys.utils.Mensagens;
import sys.utils.Utils;
import static sys.utils.Utils.codCorreto;
import static sys.utils.Utils.escClose;

public class UIAnalisaPedidos extends javax.swing.JDialog {

    PrintService ps[];
    PrintService impressora;
    NumberFormat formMoeda = NumberFormat.getCurrencyInstance();

    public UIAnalisaPedidos() {
    }

    /**
     * Creates new form UIAnalisaValeMercadoria
     *
     * @param parent
     * @param modal
     */
    public UIAnalisaPedidos(java.awt.Dialog parent, boolean modal) {
        super(parent, modal);
        initComponents();
        escClose(this);
        this.setIconImage(new ImageIcon(getClass().getResource("/sys/picture/icon.png")).getImage());
        setLocationRelativeTo(null);
        detectarImpressoras();
        setResizable(false);
        UIManager.put("Table.alternateRowColor", new java.awt.Color(230, 255, 255));
    }

    public UIAnalisaPedidos(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        escClose(this);
        this.setIconImage(new ImageIcon(getClass().getResource("/sys/picture/icon.png")).getImage());
        setLocationRelativeTo(null);
        detectarImpressoras();
        setResizable(false);
        UIManager.put("Table.alternateRowColor", new java.awt.Color(230, 255, 255));
    }

    private void detectarImpressoras() {
        try {
            jbImpressora.removeAllItems();
            DocFlavor df = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
            ps = PrintServiceLookup.lookupPrintServices(df, null);

            for (PrintService p : ps) {
                jbImpressora.addItem(p.getName());
            }
        } catch (Exception e) {
            Mensagens.msgErro("Erro Ao Encontrar Impressoras\n" + e.getMessage());
        }
    }

    private String gerarStringImpressao() {

        String impressao = "";
        String nPedido = codCorreto(txPedido.getText(), 7);

        double custo = 0;
        double venda = 0;
        double margem = 0;

        try {
            List<PedidoBean> tipoData = PedidoDao.tipoData(nPedido);
            if (tipoData.size() < 1 || nPedido.equals("")) {
                Mensagens.msgAtencao("pedido não encontrado.");
            } else {

                if (tipoData.get(0).getTipo().equals("P")) {

                    impressao += "----- VOVO JOAO MAT. PARA CONSTRUCAO ------\n";
                    impressao += "DATA: " + Utils.dataCorreta(tipoData.get(0).getData()) + " \nPEDIDO: " + nPedido + "\n";
                    impressao += " -----------------------------------------------\n";
                    impressao += "                *** PEDIDO ***               \n";
                    impressao += " -----------------------------------------------\n";
                    impressao += "CODIGO ------------ DESCRICAO ------------------\n";
                } else {
                    impressao += "----- VOVO JOAO MAT. PARA CONSTRUCAO ------\n";
                    impressao += "DATA: " + Utils.dataCorreta(tipoData.get(0).getData()) + " \nPEDIDO: " + nPedido + "\n";
                    impressao += " -----------------------------------------------\n";
                    impressao += "                *** ORCAMENTO ***               \n";
                    impressao += " -----------------------------------------------\n";
                    impressao += "CODIGO ------------ DESCRICAO ------------------\n";
                }

                int i = 0;//utilizado para calcular a margem
                for (PedidoBean pedido : PedidoDao.listaDados(nPedido)) {

                    impressao += pedido.getProduto().getCodigo() + " - ";
                    impressao += pedido.getProduto().getDescricao() + "\n";
                    impressao += pedido.getiPedido().getQtdProdutoCompra() + "  ";
                    impressao += "CUSTO UNT.: " + pedido.getProduto().getpCusto() + "  ";
                    impressao += "VENDA UNT.: " + pedido.getiPedido().getPvenda() + "\n";

                    BigDecimal pCustoTotal = new BigDecimal(pedido.getProduto().getpCusto() * pedido.getiPedido().getQtdProdutoCompra()).setScale(2, RoundingMode.HALF_DOWN);
                    BigDecimal pVendaTotal = new BigDecimal(pedido.getiPedido().getPvenda() * pedido.getiPedido().getQtdProdutoCompra()).setScale(2, RoundingMode.HALF_DOWN);

                    impressao += "TOTAL CUSTO:  R$ " + pCustoTotal + "\n";
                    impressao += "TOTAL VENDA:  R$ " + pVendaTotal + "\n";

                    BigDecimal markupUnt = new BigDecimal(pedido.getProduto().getMarkup()).setScale(2, RoundingMode.HALF_DOWN);

                    impressao += "MARKUP UNT.:   % " + markupUnt + "\n";
                    impressao += " -----------------------------------------------\n";

                    custo += (pedido.getProduto().getpCusto() * pedido.getiPedido().getQtdProdutoCompra());
                    venda += (pedido.getiPedido().getPvenda() * pedido.getiPedido().getQtdProdutoCompra());

                    margem += pedido.getProduto().getMarkup();
                    i++;

                }

                BigDecimal custoArredondado = new BigDecimal(custo).setScale(2, RoundingMode.HALF_DOWN);
                BigDecimal VendaArredondado = new BigDecimal(venda).setScale(2, RoundingMode.HALF_DOWN);
                BigDecimal margemFinalArd = new BigDecimal(margem / i).setScale(2, RoundingMode.HALF_DOWN);

                impressao += "CUSTO BRUTO TOTAL.................: R$ " + custoArredondado + "\n";
                impressao += "VENDA BRUTO TOTAL.................: R$ " + VendaArredondado + "\n";
                impressao += "MARKUP FINAL SOBRE CUSTO..........:  % " + margemFinalArd + "\n";
                impressao += " -----------------------------------------------\n";

                double desconto = PedidoDao.desconto(nPedido, tipoData.get(0).getTipo());
                double acrescimo = PedidoDao.acrescimo(nPedido);

                double venda_desconto = venda - desconto;
                double venda_acrescimo = venda + acrescimo;

                BigDecimal margemDesAr = new BigDecimal((((venda_desconto / custo) - 1) * 100)).setScale(2, RoundingMode.HALF_DOWN);
                BigDecimal margemAcrAr = new BigDecimal((((venda_acrescimo / custo) - 1) * 100)).setScale(2, RoundingMode.HALF_DOWN);

                impressao += "TOTAL DE DESCONTO...........: R$ " + desconto + "\n";
                impressao += "TOTAL DE ACRESCIMO..........: R$ " + acrescimo + "\n";
                impressao += " -----------------------------------------------\n";

                BigDecimal venda_desconto_arre = new BigDecimal(venda_desconto).setScale(2, RoundingMode.HALF_DOWN);
                BigDecimal venda_acrescimo_arre = new BigDecimal(venda_acrescimo).setScale(2, RoundingMode.HALF_DOWN);

                impressao += "VENDA BRUTO - DESCONTO...........: R$ " + venda_desconto_arre + "\n";
                impressao += "MARKUP FINAL - DESCONTO..........:  % " + margemDesAr + "\n";
                impressao += " -----------------------------------------------\n";
                impressao += "VENDA BRUTO + ACRESCIMO...........: R$ " + venda_acrescimo_arre + "\n";
                impressao += "MARKUP FINAL + ACRESCIMO..........:  % " + margemAcrAr + "\n";
                impressao += " -----------------------------------------------\n";
                impressao += "\n\n";

            }
        } catch (SQLException | IOException ex) {
            Mensagens.msgErro("Erro\n" + ex.getMessage());
        }
        return impressao + (char) 27 + (char) 109;
    }

    private void atualizaTabela() {

        String nPedido = codCorreto(txPedido.getText(), 7);

        double custo = 0;
        double venda = 0;

        try {

            List<PedidoBean> tipoData = PedidoDao.tipoData(nPedido);

            if (tipoData.size() < 1) {
                Mensagens.msgAtencao("pedido não encontrado.");

            } else {

                if (tipoData.get(0).getTipo().equals("P")) {
                    lbTipo.setText("PEDIDO:");
                } else {
                    lbTipo.setText("ORÇAMENTO:");
                }
                txData.setText(Utils.dataCorreta(tipoData.get(0).getData()));

                DefaultTableModel modelo = (DefaultTableModel) tabela.getModel();
                modelo.setNumRows(0);

                for (PedidoBean pedido : PedidoDao.listaDados(nPedido)) {
                    /*
                     * total de custo e total de venda do item para jogar na
                     * tabela
                     */
                    BigDecimal pCustoTotal = new BigDecimal(pedido.getProduto().getpCusto() * pedido.getiPedido().getQtdProdutoCompra()).setScale(2, RoundingMode.HALF_DOWN);
                    BigDecimal pVendaTotal = new BigDecimal(pedido.getiPedido().getPvenda() * pedido.getiPedido().getQtdProdutoCompra()).setScale(2, RoundingMode.HALF_DOWN);

                    /*
                     * total de custo e total de venda final para jogar na
                     * tabela
                     */
                    custo += (pedido.getProduto().getpCusto() * pedido.getiPedido().getQtdProdutoCompra());
                    venda += (pedido.getiPedido().getPvenda() * pedido.getiPedido().getQtdProdutoCompra());
                    /*
                     * markup e margem arredondados para jogar na tabela
                     */
                    BigDecimal margemTabela = new BigDecimal(pedido.getProduto().getMargem()).setScale(2, RoundingMode.HALF_DOWN);
                    BigDecimal markupTabela = new BigDecimal(pedido.getProduto().getMarkup()).setScale(2, RoundingMode.HALF_DOWN);

                    modelo.addRow(new Object[]{
                        pedido.getProduto().getDescricao(), formMoeda.format(pedido.getiPedido().getQtdProdutoCompra()).replace("R$", ""),
                        formMoeda.format(pedido.getProduto().getpCusto()).replace("R$", ""), formMoeda.format(pedido.getiPedido().getPvenda()).replace("R$", ""),
                        formMoeda.format(pCustoTotal).replace("R$", ""), formMoeda.format(pVendaTotal).replace("R$", ""), formMoeda.format(markupTabela).replace("R$", "") + " %",
                        formMoeda.format(margemTabela).replace("R$", "") + " %"
                    });
                }

//                DefaultTableCellRenderer centralizado = new DefaultTableCellRenderer();
//
//                centralizado.setHorizontalAlignment(SwingConstants.CENTER);
//                tabela.getColumnModel().getColumn(1).setCellRenderer(centralizado);
//                tabela.getColumnModel().getColumn(2).setCellRenderer(centralizado);
//                tabela.getColumnModel().getColumn(3).setCellRenderer(centralizado);
//                tabela.getColumnModel().getColumn(4).setCellRenderer(centralizado);
//                tabela.getColumnModel().getColumn(5).setCellRenderer(centralizado);
//                tabela.getColumnModel().getColumn(6).setCellRenderer(centralizado);
//                tabela.getColumnModel().getColumn(7).setCellRenderer(centralizado);
                tabela.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {

                    @Override
                    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                        super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                        String ref = table.getValueAt(row, 6).toString();

                        if (Double.parseDouble(Utils.numParaCalculos(ref)) <= 25) {
                            setOpaque(true);
                            setForeground(new java.awt.Color(255, 0, 0));//Altera para esta cor. 

                        } else if (Double.parseDouble(Utils.numParaCalculos(ref)) > 15 && Double.parseDouble(Utils.numParaCalculos(ref)) <= 40) {
                            setOpaque(true);
                            setForeground(new java.awt.Color(255, 140, 0));
                        } else if (Double.parseDouble(Utils.numParaCalculos(ref)) > 40 && Double.parseDouble(Utils.numParaCalculos(ref)) <= 60) {
                            setOpaque(true);
                            setForeground(new java.awt.Color(0, 0, 255));
                        } else if (Double.parseDouble(Utils.numParaCalculos(ref)) > 60) {
                            setOpaque(true);
                            setForeground(new java.awt.Color(255, 0, 255));
                        } else {
                            setForeground(null);
                        }
                        return this;
                    }
                });

//                DefaultTableCellRenderer centralizado = new DefaultTableCellRenderer();
//                centralizado.setHorizontalAlignment(SwingConstants.CENTER);
//                tabela.getColumnModel().getColumn(1).setCellRenderer(centralizado);
//                tabela.getColumnModel().getColumn(2).setCellRenderer(centralizado);
//                tabela.getColumnModel().getColumn(3).setCellRenderer(centralizado);
//                tabela.getColumnModel().getColumn(4).setCellRenderer(centralizado);
//                tabela.getColumnModel().getColumn(5).setCellRenderer(centralizado);
//                tabela.getColumnModel().getColumn(6).setCellRenderer(centralizado);
//                tabela.getColumnModel().getColumn(7).setCellRenderer(centralizado);
                BigDecimal custoArredondado = new BigDecimal(custo).setScale(2, RoundingMode.HALF_DOWN);
                //BigDecimal totalVendaArre = new BigDecimal(venda).setScale(2, RoundingMode.HALF_DOWN);
                double desconto = PedidoDao.desconto(nPedido, tipoData.get(0).getTipo());
                double acrescimo = PedidoDao.acrescimo(nPedido);

                double vendaFinal = venda + (acrescimo - desconto);

                //BigDecimal vendaFinal = new BigDecimal((venda - PedidoDao.desconto(nPedido)) + PedidoDao.acrescimo(nPedido)).setScale(2, RoundingMode.HALF_DOWN);
                txNPedido.setText(nPedido);
                txTotalBruto.setText("" + formMoeda.format(venda));
                txTotalCusto.setText("" + formMoeda.format(custoArredondado));
                txTotalVenda.setText("" + formMoeda.format(vendaFinal));

                txTotalAcrescimo.setText("" + formMoeda.format(acrescimo));
                txTotalDesconto.setText("" + formMoeda.format(desconto));

                double markupFinal = (((vendaFinal / custo) - 1) * 100);
                double margemFinal = (((vendaFinal - custo) / vendaFinal) * 100);

                BigDecimal markupArred = new BigDecimal(markupFinal).setScale(2, RoundingMode.HALF_DOWN);
                BigDecimal margemArred = new BigDecimal(margemFinal).setScale(2, RoundingMode.HALF_DOWN);

                txMarkup.setText("% " + markupArred.toString().replace(".", ","));
                txMargem.setText("% " + margemArred.toString().replace(".", ","));
            }

        } catch (SQLException | IOException ex) {
            Mensagens.msgErro("Erro\n" + ex.getMessage());
        }

    }

    private void imprimir() {

        for (int i = 0; i < 1; i++) {
            // Conteúdo a ser impresso '\u039A' utilizado para cortar o papel
            InputStream stream = new ByteArrayInputStream((gerarStringImpressao() + "\u039A").getBytes());

            impressora = ps[jbImpressora.getSelectedIndex()];

            DocPrintJob dpj = impressora.createPrintJob();

            // Definição de atributos do conteúdo a ser impresso:  
            DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;

            // Cria um Doc para impressão a partir do arquivo exemplo.txt 
            Doc documentoTexto = new SimpleDoc(stream, flavor, null);

            try {
                //  Imprime o documento sem exibir uma tela de dialogo 
                dpj.print(documentoTexto, null);
            } catch (PrintException ex) {
                Mensagens.msgErro("erro ao imprimir, certifique-se de que a impressora foi selecionada corretamente!\n" + ex);
            }
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabela = new javax.swing.JTable();
        jPanel4 = new javax.swing.JPanel();
        txPedido = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jbImpressora = new javax.swing.JComboBox();
        jPanel6 = new javax.swing.JPanel();
        lbTipo = new javax.swing.JLabel();
        txNPedido = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        lbTipo1 = new javax.swing.JLabel();
        txData = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        txTotalDesconto = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        txTotalAcrescimo = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        txMargem = new javax.swing.JTextField();
        txTotalBruto = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txTotalCusto = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        txTotalVenda = new javax.swing.JTextField();
        txMarkup = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        jPanel8 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jPanel9 = new javax.swing.JPanel();
        jLabel14 = new javax.swing.JLabel();
        jPanel10 = new javax.swing.JPanel();
        btnSalvar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        btnSair = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("ANALISE DE PEDIDOS");

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        tabela.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));
        tabela.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        tabela.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "DESCRICAO", "QTD.", "CUSTO UNT", "VENDA UNT", "TOTAL CUSTO", "TOTAL VENDA", "MARKUP", "MARGEM BRUTA"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabela.setGridColor(new java.awt.Color(204, 204, 204));
        tabela.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(tabela);
        if (tabela.getColumnModel().getColumnCount() > 0) {
            tabela.getColumnModel().getColumn(0).setPreferredWidth(180);
            tabela.getColumnModel().getColumn(1).setPreferredWidth(10);
            tabela.getColumnModel().getColumn(2).setPreferredWidth(18);
            tabela.getColumnModel().getColumn(3).setPreferredWidth(18);
            tabela.getColumnModel().getColumn(4).setPreferredWidth(20);
            tabela.getColumnModel().getColumn(5).setPreferredWidth(20);
            tabela.getColumnModel().getColumn(6).setPreferredWidth(15);
            tabela.getColumnModel().getColumn(7).setPreferredWidth(15);
        }

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));
        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "PREENCHA CAMPOS:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 0, 10))); // NOI18N

        txPedido.setBackground(new java.awt.Color(245, 245, 245));
        txPedido.setFont(new java.awt.Font("Calibri", 0, 18)); // NOI18N
        txPedido.setForeground(new java.awt.Color(0, 51, 255));
        txPedido.setBorder(null);
        txPedido.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txPedidoActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel1.setText("PEDIDO:");

        jLabel2.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel2.setText("IMPRESSORA:");

        jbImpressora.setBackground(new java.awt.Color(245, 245, 245));
        jbImpressora.setEditable(true);
        jbImpressora.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        jbImpressora.setToolTipText("Certifique-se de ter uma impressora térmica instalada.");
        jbImpressora.setBorder(null);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txPedido, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jbImpressora, 0, 188, Short.MAX_VALUE)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txPedido, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbImpressora, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel6.setBackground(new java.awt.Color(255, 255, 255));
        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "DADOS DO PEDIDO:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 0, 10))); // NOI18N

        lbTipo.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        lbTipo.setText("TIPO:");

        txNPedido.setEditable(false);
        txNPedido.setBackground(new java.awt.Color(245, 245, 245));
        txNPedido.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        txNPedido.setForeground(new java.awt.Color(0, 0, 255));
        txNPedido.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txNPedido.setBorder(null);

        jLabel11.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel11.setText("MARKUP FINAL LIQUIDO:");

        lbTipo1.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        lbTipo1.setText("DATA:");

        txData.setEditable(false);
        txData.setBackground(new java.awt.Color(245, 245, 245));
        txData.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        txData.setForeground(new java.awt.Color(0, 0, 255));
        txData.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txData.setBorder(null);

        jLabel12.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel12.setText("TOTAL DE DESCONTO:");

        txTotalDesconto.setEditable(false);
        txTotalDesconto.setBackground(new java.awt.Color(245, 245, 245));
        txTotalDesconto.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        txTotalDesconto.setForeground(new java.awt.Color(0, 0, 255));
        txTotalDesconto.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txTotalDesconto.setBorder(null);

        jLabel13.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel13.setText("TOTAL DE ACRÉSCIMO:");

        txTotalAcrescimo.setEditable(false);
        txTotalAcrescimo.setBackground(new java.awt.Color(245, 245, 245));
        txTotalAcrescimo.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        txTotalAcrescimo.setForeground(new java.awt.Color(0, 0, 255));
        txTotalAcrescimo.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txTotalAcrescimo.setBorder(null);

        jLabel15.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel15.setText("MARGEM FINAL LIQUIDO:");

        txMargem.setEditable(false);
        txMargem.setBackground(new java.awt.Color(245, 245, 245));
        txMargem.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        txMargem.setForeground(new java.awt.Color(51, 0, 255));
        txMargem.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txMargem.setBorder(null);

        txTotalBruto.setEditable(false);
        txTotalBruto.setBackground(new java.awt.Color(245, 245, 245));
        txTotalBruto.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        txTotalBruto.setForeground(new java.awt.Color(51, 0, 255));
        txTotalBruto.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txTotalBruto.setBorder(null);

        jLabel8.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel8.setText("TOTAL BRUTO:");

        jLabel6.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel6.setText("TOTAL DE CUSTO:");

        txTotalCusto.setEditable(false);
        txTotalCusto.setBackground(new java.awt.Color(245, 245, 245));
        txTotalCusto.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        txTotalCusto.setForeground(new java.awt.Color(51, 0, 255));
        txTotalCusto.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txTotalCusto.setBorder(null);

        jLabel7.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel7.setText("TOTAL VENDA FINAL:");

        txTotalVenda.setEditable(false);
        txTotalVenda.setBackground(new java.awt.Color(245, 245, 245));
        txTotalVenda.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        txTotalVenda.setForeground(new java.awt.Color(51, 0, 255));
        txTotalVenda.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txTotalVenda.setBorder(null);

        txMarkup.setEditable(false);
        txMarkup.setBackground(new java.awt.Color(245, 245, 245));
        txMarkup.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        txMarkup.setForeground(new java.awt.Color(51, 0, 255));
        txMarkup.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txMarkup.setBorder(null);

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap(59, Short.MAX_VALUE)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbTipo)
                            .addComponent(txNPedido, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addComponent(lbTipo1)
                                .addGap(209, 209, 209))
                            .addComponent(txData, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(txTotalVenda, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(txMarkup, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                                    .addComponent(txTotalCusto)
                                    .addGap(6, 6, 6))
                                .addGroup(jPanel6Layout.createSequentialGroup()
                                    .addComponent(jLabel6)
                                    .addGap(47, 47, 47)))
                            .addComponent(jLabel7))
                        .addGap(12, 12, 12)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel11)
                            .addComponent(jLabel12)
                            .addComponent(txTotalDesconto, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(jLabel8))
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addGap(20, 20, 20)
                                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txMargem)
                                    .addComponent(jLabel15)))
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel13)
                                    .addComponent(txTotalAcrescimo, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txTotalBruto, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))))))
                .addGap(57, 57, 57))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbTipo)
                    .addComponent(lbTipo1)
                    .addComponent(jLabel8))
                .addGap(1, 1, 1)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txNPedido, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txData, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txTotalBruto, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jLabel12)
                    .addComponent(jLabel13))
                .addGap(2, 2, 2)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txTotalDesconto, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txTotalAcrescimo, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txTotalCusto, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txTotalVenda, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txMarkup, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txMargem, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "LEGENDA:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 0, 10))); // NOI18N

        jPanel3.setBackground(new java.awt.Color(255, 50, 50));

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 10, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 10, Short.MAX_VALUE)
        );

        jLabel3.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel3.setText("<= 25% Markup");

        jLabel4.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel4.setText("> 15 <= 40% Markup");

        jPanel7.setBackground(new java.awt.Color(255, 153, 0));

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 10, Short.MAX_VALUE)
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 10, Short.MAX_VALUE)
        );

        jPanel8.setBackground(new java.awt.Color(51, 51, 255));

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 10, Short.MAX_VALUE)
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 10, Short.MAX_VALUE)
        );

        jLabel5.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel5.setText("> 40 <= 60% Markup");

        jPanel9.setBackground(new java.awt.Color(255, 51, 255));

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 10, Short.MAX_VALUE)
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 10, Short.MAX_VALUE)
        );

        jLabel14.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel14.setText("> 60% Markup");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel14)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel3)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(29, 29, 29))
        );

        jPanel10.setBackground(new java.awt.Color(255, 255, 255));
        jPanel10.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(204, 204, 204), 1, true));

        btnSalvar.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        btnSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/picture/find-2.png"))); // NOI18N
        btnSalvar.setText("VISUALISAR");
        btnSalvar.setPreferredSize(new java.awt.Dimension(120, 30));
        btnSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalvarActionPerformed(evt);
            }
        });
        jPanel10.add(btnSalvar);

        btnCancelar.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/picture/print.png"))); // NOI18N
        btnCancelar.setText("IMPRIMIR");
        btnCancelar.setPreferredSize(new java.awt.Dimension(120, 30));
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });
        jPanel10.add(btnCancelar);

        btnSair.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        btnSair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/picture/sair.png"))); // NOI18N
        btnSair.setText("SAIR");
        btnSair.setPreferredSize(new java.awt.Dimension(120, 30));
        btnSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSairActionPerformed(evt);
            }
        });
        jPanel10.add(btnSair);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel10, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 309, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txPedidoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txPedidoActionPerformed
        if (txPedido.getText().equals("")) {
            Mensagens.msgErro("Informe número do pedido!");
        } else {

            final BarraProgresso pb = new BarraProgresso(this);
            SwingWorker worker = new SwingWorker() {

                @Override
                protected Object doInBackground() throws Exception {
                    pb.gerarJanela();
                    atualizaTabela();
                    return null;
                }

                @Override
                protected void done() {
                    pb.fechar();
                }
            };
            worker.execute();
        }
    }//GEN-LAST:event_txPedidoActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        if (txPedido.getText().equals("")) {
            Mensagens.msgAtencao("Informe número do pedido!");
        } else {

            final BarraProgresso pb = new BarraProgresso(this);
            SwingWorker worker = new SwingWorker() {

                @Override
                protected Object doInBackground() throws Exception {
                    pb.gerarJanela();
                    imprimir();
                    return null;
                }

                @Override
                protected void done() {
                    pb.fechar();
                }
            };
            worker.execute();

        }
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalvarActionPerformed
        if (txPedido.getText().equals("")) {
            Mensagens.msgAtencao("Informe número do pedido!");
            txPedido.requestFocus();
        } else {
            final BarraProgresso pb = new BarraProgresso(this);
            SwingWorker worker = new SwingWorker() {

                @Override
                protected Object doInBackground() throws Exception {
                    pb.gerarJanela();
                    atualizaTabela();
                    return null;
                }

                @Override
                protected void done() {
                    pb.fechar();
                }
            };
            worker.execute();
        }
    }//GEN-LAST:event_btnSalvarActionPerformed

    private void btnSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSairActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnSairActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnSair;
    private javax.swing.JButton btnSalvar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JComboBox jbImpressora;
    private javax.swing.JLabel lbTipo;
    private javax.swing.JLabel lbTipo1;
    private javax.swing.JTable tabela;
    private javax.swing.JTextField txData;
    private javax.swing.JTextField txMargem;
    private javax.swing.JTextField txMarkup;
    private javax.swing.JTextField txNPedido;
    public javax.swing.JTextField txPedido;
    private javax.swing.JTextField txTotalAcrescimo;
    private javax.swing.JTextField txTotalBruto;
    private javax.swing.JTextField txTotalCusto;
    private javax.swing.JTextField txTotalDesconto;
    private javax.swing.JTextField txTotalVenda;
    // End of variables declaration//GEN-END:variables
}
